package com.lee.boot.head.first.demo.controller;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttribute;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping(value = "/session")
@SessionAttributes(names = "user", types = Long.class)
public class SessionController {


    @RequestMapping("/get")
    public String addSession(@SessionAttribute(name = "user_id") Long id, ModelAndView modelAndView) {
        System.out.println(id);
        modelAndView.addObject("user", 123L);
        return id + "";
    }

    /**
     * @Description: 从请求的header中获取参数
     * @author: Lee
     * @Date: 2019/11/23
     */
    @RequestMapping("/header")
    public String getHeader(@RequestHeader(name = "id") Long id, ModelAndView modelAndView) {
        System.out.println(id);
        modelAndView.addObject("id", id);
        return id + "";
    }

}
